import sys
sys.path.append('.')

from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
from main_view import Ui_MainWindow

from lib_plugin import Plugin, Module, PluginManager


def onclick():
    print('clicked')
    _module = PluginManager.get_module('.', 'plugins.demo_module')
    if _module:
        module = Module(_module)
        module.init()
        module.destory()

    _plugin_classA = PluginManager.get_class('.', 'plugins.demo_module', 'ClsA')
    if _plugin_classA:
        pluginA = Plugin(_plugin_classA)
        pluginA.init()
        pluginA.destory()

    _plugin_classB = PluginManager.get_class('.', 'plugins.demo_module', 'ClsB')
    if _plugin_classB:
        pluginB = Plugin(_plugin_classB)
        pluginB.init()
        pluginB.destory()


app = QApplication(sys.argv)
mainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(mainWindow)
mainWindow.show()

ui.pushButton.clicked.connect(onclick)

sys.exit(app.exec_())
